package com.kuiandjie.web;


import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kuiandjie.entity.FileType;
import com.kuiandjie.entity.Files;
import com.kuiandjie.service.FileService;
import com.kuiandjie.service.FileTypeService;

public class FileListServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		
		String folderid = request.getParameter("fid"); 
		if(folderid == null || "".equals(folderid)){
			response.sendRedirect("file.jspx");
			return;
		}
		HttpSession session = request.getSession();
		
		FileTypeService fts = new FileTypeService();
		FileType ft = fts.findFTByFTId(folderid);
		
		if(ft == null){
			response.sendRedirect("file.jspx");
			return;
		}
		session.setAttribute("foldername", ft.getName());
		session.setAttribute("folderid", folderid);
		
			FileService fs = new FileService();
			
			List<Files> filelist = fs.findAllByFileTypeId(folderid);
			request.setAttribute("filelist", filelist);
			request.getRequestDispatcher("WEB-INF/views/filelist.jsp").forward(request, response);
	
		
	}

}
